// AUTHORS:		P. Edwards, K. O'Keefe, B. Weaver, Z. Wheeler
// COURSE:		COMP 244, Database Management Systems
// DATE:		13 December 2011
// DESCRIPTION:	The header file "OrderedDataSet.h"  contains the definitions of the
//				base class OrderedDataSet and its member functions.

#ifndef _244_FINAL_PROJECT_ORDERED_DATA_SET_H_
#define _244_FINAL_PROJECT_ORDERED_DATA_SET_H_

#include <deque>;
using std::deque;


template<typename T>
class DataSet : public Uncopyable {
private:
    bool loaded;

protected:
    deque<T> data;

public:
    DataSet() : loaded(false) {}
    ~DataSet() {}
    
    int size() {
	    return data.size();
    }
	
    T& get(int idx) {
        return data.at(idx);
    }
    
    const T& get(int idx) const {
        return data.at(idx);
    }

    //will need to be overriden by subclasses
    void load();
    
    //may need to be overriden by subclasses
    void clear() {
        data.clear();
    }
    
    void isLoaded() { return loaded; }
};

template<typename T>
class OrderedDataSet : public DataSet {
public:
    OrderedDataSet() {}
    ~OrderedDataSet() {}
    
    //useful operations, some of which will need to be overridden to perform 
    // updates on the database
    
    void remove(int) {
        data.erase(data.begin() + idx);
    }
    
    void add(const T &addedData, int idx = songs.size()) {
        data.insert(data.begin() + idx, addedData);
    }
    
    void move(int from_idx, int to_idx) {
        if(from_idx <= to_idx)
		    --to_idx;

	    T temp = data.at(from_idx);

	    data.erase(data.begin() + from_idx);

	    data.insert(data.begin() + to_idx, temp);
    }
    
    void swap(int idx1, int idx2) {
        T temp = data.at(idx1);
	
	    data.at(idx1) = data.at(idx2);
	    data.at(idx2) = temp;
	}
};


#endif // inclusion guard

